package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark81Binding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark81 extends BaseMark {

    LayoutWatermark81Binding binding;

    public Mark81(@NonNull Context context) {
        super(context);
    }

    public Mark81(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark81(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark81Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
            hideView(binding.binding34);
            for (int i = 3; i < binding.mid.getChildCount(); i++) {
                binding.mid.getChildAt(i).setVisibility(View.GONE);
            }
        } else {
            binding = LayoutWatermark81Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    @Override
    public void update() {
        setText(binding.binding1, "title81", binding.binding1);
        setText(binding.binding3, "time81", binding.binding2);
        setTime(binding.binding3, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));

        setText(binding.binding5, "part81", binding.binding4);
        setText(binding.binding7, "content81", binding.binding6);
        setText(binding.binding9, "shigong81", binding.binding8);
        setText(binding.binding11, "weather81", binding.binding10);

        setText(binding.binding13, "didian81", binding.binding12);
        setText(binding.binding15, "height81", binding.binding14);

        setText(binding.binding17, "jingwei81", binding.binding16);
        String[] ss = new EditItem("jingwei81").getStringPoints();
        binding.binding17.setText(ss[1]);
        binding.binding19.setText(ss[0]);


        setText(binding.binding21, "check81", binding.binding21);
        setText(binding.binding23, "beizhu81", binding.binding24);

        setText(binding.binding25, "jianshedanwei81", binding.binding24);
        setText(binding.binding27, "jianlidanwei81", binding.binding26);
        setText(binding.binding29, "shigongdanwei81", binding.binding28);
        setText(binding.binding31, "shejidanwei81", binding.binding30);
        setText(binding.binding33, "kanchadanwei81", binding.binding32);

        setText(binding.bottom.binding1, "tip81", binding.binding34);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("title81", "标题"));
        list.add(new EditItem("time81", "时间", true));
        list.add(new EditItem("part81", "工程部位"));
        list.add(new EditItem("content81", "工程内容"));
        list.add(new EditItem("shigong81", "施工人员"));
        list.add(new EditItem("weather81", "天气"));
        list.add(new EditItem("didian81", "地点"));
        list.add(new EditItem("height81", "海拔"));
        list.add(new EditItem("jingwei81", "经纬度"));
        list.add(new EditItem("check81", "监理人员"));
        list.add(new EditItem("beizhu81", "备注"));

        list.add(new EditItem("jianshedanwei81", "建设单位"));
        list.add(new EditItem("jianlidanwei81", "监理单位"));
        list.add(new EditItem("shigongdanwei81", "施工单位"));
        list.add(new EditItem("shejidanwei81", "设计单位"));
        list.add(new EditItem("kanchadanwei81", "勘察单位"));
        list.add(new EditItem("tip81", "提示语"));

        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding3, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        } else if (item.isPoint()) {
            String[] ss = new EditItem("jingwei81").getStringPoints();
            binding.binding17.setText(ss[1]);
            binding.binding19.setText(ss[0]);
        } else {
            super.onValueChange(item);
        }
    }

    @Override
    public void onShowChange(EditItem item) {
        if (item.isPoint()) {
            if (item.show) {
                showView(binding.binding16, binding.binding18);
            } else {
                hideView(binding.binding16, binding.binding18);
            }
        } else {
            super.onShowChange(item);
        }
    }
}
